from openai import OpenAI

# 初始化客户端
client = OpenAI(
    api_key="sk-xgxbqajfxbsfptqumdbsrtiakcisgochhzyltatkcqtarlvq",  # 从https://cloud.siliconflow.cn/account/ak获取
    base_url="https://api.siliconflow.cn/v1"
)

# 测试不同参数组合
test_params = [
    {"max_tokens": 100, "temperature": 0, "frequency_penalty": 0.2},
    {"max_tokens": 500, "temperature": 0, "frequency_penalty": 0.2, 'top_p': 0.9, 'top_k': 10},
    {"max_tokens": 500, "temperature": 0.7, "frequency_penalty": 1.2, 'top_p': 0.9, 'top_k': 50},
    {"max_tokens": 500, "temperature": 1.0, "frequency_penalty": 2.0, 'top_p': 0.7, 'top_k': 50}
]

# 循环测试不同参数组合
for params in test_params:
    print(f"\n测试参数: {params}")
    
    response = client.chat.completions.create(
        model="deepseek-ai/DeepSeek-V2.5",  # 选择合适的模型
        messages=[
            {"role": "user", "content": "请用不同的方式描述春天的景色"}
        ],
        max_tokens=params["max_tokens"],
        temperature=params["temperature"],
        frequency_penalty=params["frequency_penalty"],  # 使用frequency_penalty替代repetition_penalty
        stream=True
    )
    
    print("生成结果:")
    content = ""
    for chunk in response:
        if chunk.choices[0].delta.content:
            content += chunk.choices[0].delta.content
            print(chunk.choices[0].delta.content, end="")
    print("\n" + "-"*50)
